<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Basic PECL/haru example</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="haru.examples.html">范例</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="haru.builtin.html">Builtin Fonts And Encodings</a></div>
 <div class="up"><a href="haru.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="haru.examples-basics" class="section">
  <h2 class="title">Basic PECL/haru example</h2>
  <p class="para">
   <div class="example" id="example-3442">
    <p><strong>Example #1 Fancy &quot;Hello world&quot;</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$doc&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">HaruDoc</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setPageMode</span><span style="color: #007700">(</span><span style="color: #0000BB">HaruDoc</span><span style="color: #007700">::</span><span style="color: #0000BB">PAGE_MODE_USE_THUMBS</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">/*&nbsp;show&nbsp;thumbnails&nbsp;*/<br /><br /></span><span style="color: #0000BB">$page&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addPage</span><span style="color: #007700">();&nbsp;</span><span style="color: #FF8000">/*&nbsp;add&nbsp;page&nbsp;to&nbsp;the&nbsp;document&nbsp;*/<br /></span><span style="color: #0000BB">$page</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setSize</span><span style="color: #007700">(</span><span style="color: #0000BB">HaruPage</span><span style="color: #007700">::</span><span style="color: #0000BB">SIZE_A4</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">HaruPage</span><span style="color: #007700">::</span><span style="color: #0000BB">LANDSCAPE</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">/*&nbsp;set&nbsp;the&nbsp;page&nbsp;to&nbsp;use&nbsp;A4&nbsp;landscape&nbsp;format&nbsp;*/<br /><br /></span><span style="color: #0000BB">$courier&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getFont</span><span style="color: #007700">(</span><span style="color: #DD0000">"Courier-Bold"</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">/*&nbsp;we'll&nbsp;use&nbsp;the&nbsp;bundled&nbsp;font&nbsp;a&nbsp;few&nbsp;lines&nbsp;below&nbsp;*/<br /><br /></span><span style="color: #0000BB">$page</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setRGBStroke</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">/*&nbsp;set&nbsp;colors&nbsp;*/<br /></span><span style="color: #0000BB">$page</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setRGBFill</span><span style="color: #007700">(</span><span style="color: #0000BB">0.7</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0.8</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0.9</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$page</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">rectangle</span><span style="color: #007700">(</span><span style="color: #0000BB">150</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">150</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">550</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">250</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">/*&nbsp;draw&nbsp;a&nbsp;rectangle&nbsp;*/<br /><br /></span><span style="color: #0000BB">$page</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fillStroke</span><span style="color: #007700">();&nbsp;</span><span style="color: #FF8000">/*&nbsp;fill&nbsp;and&nbsp;stroke&nbsp;it&nbsp;*/<br /><br /></span><span style="color: #0000BB">$page</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setDash</span><span style="color: #007700">(array(</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">/*&nbsp;set&nbsp;dash&nbsp;style&nbsp;for&nbsp;lines&nbsp;at&nbsp;this&nbsp;page&nbsp;*/<br /></span><span style="color: #0000BB">$page</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setFontAndSize</span><span style="color: #007700">(</span><span style="color: #0000BB">$courier</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">60</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">/*&nbsp;set&nbsp;font&nbsp;and&nbsp;size&nbsp;*/<br /><br /></span><span style="color: #0000BB">$page</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setRGBStroke</span><span style="color: #007700">(</span><span style="color: #0000BB">0.5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0.5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0.1</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">/*&nbsp;set&nbsp;line&nbsp;color&nbsp;*/<br /></span><span style="color: #0000BB">$page</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setRGBFill</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">/*&nbsp;set&nbsp;filling&nbsp;color&nbsp;*/<br /><br /></span><span style="color: #0000BB">$page</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTextRenderingMode</span><span style="color: #007700">(</span><span style="color: #0000BB">HaruPage</span><span style="color: #007700">::</span><span style="color: #0000BB">FILL_THEN_STROKE</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">/*&nbsp;fill&nbsp;and&nbsp;stroke&nbsp;text&nbsp;*/<br /><br />/*&nbsp;print&nbsp;the&nbsp;text&nbsp;*/<br /></span><span style="color: #0000BB">$page</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">beginText</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$page</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">textOut</span><span style="color: #007700">(</span><span style="color: #0000BB">210</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">270</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Hello&nbsp;World!"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$page</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">endText</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">save</span><span style="color: #007700">(</span><span style="color: #DD0000">"/tmp/test.pdf"</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">/*&nbsp;save&nbsp;the&nbsp;document&nbsp;into&nbsp;a&nbsp;file&nbsp;*/<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   Open the result document in your favourite PDF viewer and you should see a
   light-blue rectangle and white &quot;Hello World!&quot; on it.
  </p>
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="haru.examples.html">范例</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="haru.builtin.html">Builtin Fonts And Encodings</a></div>
 <div class="up"><a href="haru.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
